package com.demo.service;

import java.util.List;

import org.apache.commons.codec.digest.DigestUtils;

import com.demo.common.constant.DictKeys;
import com.demo.common.model.AuthUser;
import com.jfinal.plugin.ehcache.CacheKit;

public class LoginService {
	public static final LoginService service = new LoginService();
	
	public int login(String username,String pwd,Boolean autoLogin){
		AuthUser user = null;
		/*List<AuthUser> userCacheList = CacheKit.get("user", username);
		if(userCacheList==null){
			//userCacheList = 
		}*/
		List<AuthUser> userList = AuthUser.me.find("select * from auth_user t where t.username=? and t.password=?"
				, username,DigestUtils.md5Hex(pwd));
		if(userList.size()!=1){
			return DictKeys.login_info_0;  //用户不存在
		}else{
			user = userList.get(0);
		}
		//判断账户是否停用
		Boolean status = user.getIsActive();
		if(!status){  
			return DictKeys.login_info_1 ;//账户禁用
		}
		//是否自动登录
		if(autoLogin){
			return DictKeys.login_info_3;
		}
		
		return 3;
	}

}
